Fully automated Video Captions generation with json2video

工作流概述

这是一个包含12个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "Tygtx1aZi9pLdtUo",
  "meta": {
    "instanceId": "8418cffce8d48086ec0a73fd90aca708aa07591f2fefa6034d87fe12a09de26e",
    "templateCredsSetupCompleted": true
  },
  "name": "Fully automated Video Captions generation with json2video",
  "tags": [],
  "nodes": [
    {
      "id": "38e862a1-dc25-4a41-b0e1-5ebba1032e0a",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -980,
        -280
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "834ac32d-4bef-4087-87af-590cd200a858",
      "name": "json2video - Add Captions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -540,
        -280
      ],
      "parameters": {
        "url": "https://api.json2video.com/v2/movies",
        "method": "POST",
        "options": {},
        "jsonBody": "={
  \"id\": \"qbaasr7s\",
  \"resolution\": \"custom\",
  \"quality\": \"high\",
\"scenes\": [
    {
      \"id\": \"qyjh9lwj\",
      \"comment\": \"Scene 1\",
      \"elements\": []
    }
  ],
  \"elements\": [
    {
      \"id\": \"q6dznzcv\",
      \"type\": \"video\",
      \"src\": \"{{ $json.video_url }}\"
    },
    {
      \"id\": \"q41n9kxp\",
      \"type\": \"subtitles\",
      \"settings\": {
        \"style\": \"classic-progressive\",
        \"font-family\": \"Oswald\",
        \"font-size\": 140,
        \"word-color\": \"#FCF5C9\",
        \"shadow-color\": \"#260B1B\",
        \"line-color\": \"#F1E7F4\",
        \"shadow-offset\": 2,
        \"box-color\": \"#260B1B\"
      },
      \"language\": \"en\"
    }
  ],
  \"width\": {{ $json.width }},
  \"height\": {{ $json.height }}
}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth"
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "FVrj0WeCT9IosZhh",
          "name": "json2video"
        },
        "httpHeaderAuth": {
          "id": "TngzgS09J1YvLIXl",
          "name": "Perplexity"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "93e98e02-a7e5-40d2-93a8-06c1ba3c4fb5",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "position": [
        -780,
        -280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "408b70d1-30ea-4f88-847d-97c59e467168",
              "name": "video_url",
              "type": "string",
              "value": "https://aiatelier.s3.eu-west-1.amazonaws.com/workflows-material/json2video/captions-sample.mp4"
            },
            {
              "id": "e54d0b14-3261-4d8c-83ac-b63a37981257",
              "name": "width",
              "type": "string",
              "value": "1080"
            },
            {
              "id": "70a87f6b-8cf1-48b0-96bf-b7a8aa5bc6da",
              "name": "height",
              "type": "string",
              "value": "1920"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d3b6d3f3-d3ca-455d-929c-ffb869bd23d8",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        -180,
        -220
      ],
      "webhookId": "f50b5765-4a91-415d-ba27-cfda281dc941",
      "parameters": {
        "amount": 10
      },
      "typeVersion": 1.1
    },
    {
      "id": "07099d4c-6012-4447-8720-af8e75521e24",
      "name": "Is Error",
      "type": "n8n-nodes-base.if",
      "position": [
        180,
        -240
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a9813eb6-0dbf-41ac-837f-8f2760cbc5e3",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.movie.status }}",
              "rightValue": "error"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a94a6b24-4674-42ac-8db4-6e9298b44b7d",
      "name": "Handle Error",
      "type": "n8n-nodes-base.noOp",
      "position": [
        420,
        -380
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "cd6bba4e-b329-4476-b983-248bb8e4423a",
      "name": "Output",
      "type": "n8n-nodes-base.set",
      "position": [
        460,
        20
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c7ce3d37-6455-407a-bf57-286d91c16f97",
              "name": "url",
              "type": "string",
              "value": "={{ $json.movie.url }}"
            },
            {
              "id": "e969f3bd-2c36-43f6-9fc3-a66a0424ec20",
              "name": "duration",
              "type": "number",
              "value": "={{ $json.movie.duration }}"
            },
            {
              "id": "a5f9b903-40c0-432e-b030-5a1fdea844db",
              "name": "size",
              "type": "number",
              "value": "={{ $json.movie.size }}"
            },
            {
              "id": "660565f1-8da7-4c2f-a5e0-b62130aef7cb",
              "name": "width",
              "type": "number",
              "value": "={{ $json.movie.width }}"
            },
            {
              "id": "5e2a9144-45e5-40f2-b71e-d74b25890ab6",
              "name": "height",
              "type": "number",
              "value": "={{ $json.movie.height }}"
            },
            {
              "id": "601f8514-61f5-4cea-9b64-373881e3c879",
              "name": "rendering_time",
              "type": "number",
              "value": "={{ $json.movie.rendering_time }}"
            },
            {
              "id": "2b7812f9-1e44-4843-b2ca-051b54153051",
              "name": "project",
              "type": "string",
              "value": "={{ $json.movie.project }}"
            },
            {
              "id": "1b562ac3-e62b-4d67-adab-2af0d15fd11e",
              "name": "remaining_quota",
              "type": "number",
              "value": "={{ $json.remaining_quota.time }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "378e027a-b033-4490-93e6-666d3d7def86",
      "name": "json2video - Get Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        0,
        -180
      ],
      "parameters": {
        "url": "=https://api.json2video.com/v2/movies?id={{ $('json2video - Add Captions').first().json.project }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth"
      },
      "credentials": {
        "httpCustomAuth": {
          "id": "FVrj0WeCT9IosZhh",
          "name": "json2video"
        },
        "httpHeaderAuth": {
          "id": "TngzgS09J1YvLIXl",
          "name": "Perplexity"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a818a3a6-4cef-4043-ac3e-96fa3f54373d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -260,
        -300
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 580,
        "content": "## Check video status"
      },
      "typeVersion": 1
    },
    {
      "id": "7258a9ec-591f-4b07-840c-3171c36f193e",
      "name": "is Completed",
      "type": "n8n-nodes-base.if",
      "position": [
        200,
        40
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2643b070-cbb2-4562-9269-a61389e0c242",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.movie.status }}",
              "rightValue": "done"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "cbce69e0-730c-46ea-bd0a-b8694bd7780d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1700,
        -480
      ],
      "parameters": {
        "width": 640,
        "height": 820,
        "content": "# Automatically Generate Captions for Your Videos with json2video

This workflow automatically adds captions to your videos using [json2video](https://json2video.com/?afco=manu), a powerful service for video automation, that integrates seamlessly with n8n.

# [👉🏻 Try json2video for free 👈🏻](https://json2video.com/?afco=manu)

## Setup

### Step 1: Create a json2video Account & API Key
1. Sign up for a [json2video account](https://json2video.com/?afco=manu).
2. Once registered, you will receive your API key via email.

### Step 2: Create n8n Credentials
1. In n8n, create new credentials and select **\"Custom Auth\"** as the type.
2. Paste the following JSON code into the credentials configuration, replacing `\"your-json2video-api-key\"` with your actual API key:

    ```json
    {
      \"headers\": {
        \"x-api-key\": \"your-json2video-api-key\"
      }
    }
    ```

### Step 3: Connect Your Credentials
1. In your n8n workflow, locate the two HTTP nodes that interact with json2video.
2. Select the credentials you created in Step 2 for both nodes.
"
      },
      "typeVersion": 1
    },
    {
      "id": "4ce3a85f-3abc-48e9-8840-f37f32490b62",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        -120
      ],
      "parameters": {
        "width": 440,
        "height": 200,
        "content": "# ☝️ Provide Video Details

For the workflow to add captions, please provide:

- **URL:** The link to your video.
- **Width & Height:** The dimensions of your video"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5d8108e2-3f44-4585-9c25-f31f95f06424",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "json2video - Get Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config": {
      "main": [
        [
          {
            "node": "json2video - Add Captions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Error": {
      "main": [
        [
          {
            "node": "Handle Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "is Completed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "is Completed": {
      "main": [
        [
          {
            "node": "Output",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "json2video - Get Status": {
      "main": [
        [
          {
            "node": "Is Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "json2video - Add Captions": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Manualtrigger
  • Httprequest
  • Set
  • Wait
  • If

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作